package wojtek_ckm;
import java.io.*;
import java.net.*;
public class Klieeeeeeee implements Runnable{

	static Socket MyClient = null;
    static PrintStream output = null;
	static DataInputStream input = null;
	static BufferedReader inputLine = null;
    static boolean closed = false;
	
    public static void main(String args[]) {
   


    	    try {
    	           MyClient = new Socket("admin-pc", 2501);
    	           inputLine = new BufferedReader(new InputStreamReader(System.in));
    	           input = new DataInputStream(MyClient.getInputStream());
        	       output = new PrintStream(MyClient.getOutputStream());

    	    
    	    } catch (UnknownHostException e) {
                System.err.println("Nie umiem znalezc tego hosta? moze sie pomysliles? ");
            } catch (IOException e) {
                System.err.println("Nie mozna nawiozac wymiany I/O z serwerem");
            }
    	    
    	    
    	    if (MyClient != null && output != null && input != null) {
                try {
    		
    		
                    new Thread(new Klieeeeeeee()).start();
    		
    		while (!closed) {
                        output.println(inputLine.readLine()); 
                    }
    	 
    	    
    	    
    	    
    	    
    	    
    	  
    	       output.close();
    	       input.close();
    	       MyClient.close();
    	    } 
    	    catch (IOException e) {
    	       System.out.println(e);
    	    }
    }
}
    
    public void run() {		
    	String responseLine;
    	
    	try{ 
    	    while ((responseLine = input.readLine()) != null) {
    		System.out.println(responseLine);
    		if (responseLine.indexOf("*** Bye") != -1) break;
    	    }
                closed=true;
    	} catch (IOException e) {
    	    System.err.println("IOException:  " + e);
    	}
        }
    }

